// 一级
import Home from "@/views/Home";
import Login from "@/views/Login";
import Register from "@/views/Register";
import Search from "@/views/Search";
import Detail from "@/views/Detail";
import AddShopSuccess from "@/views/AddCartSuccess";
import ShopCart from "@/views/ShopCart";
import Trade from "@/views/Trade";
import Pay from "@/views/Pay";
import PaySuccess from "@/views/PaySuccess";
import Center from "@/views/Center";

// 二级
import MyOrder from "@/views/Center/myOrder";
import GroupOrder from "@/views/Center/groupOrder";

// 当打包构建应用时，JavaScript 包会变得非常大，影响页面加载。
// 如果我们能把不同路由对应的组件分割成不同的代码块，然后当路由被访问的时候才加载对应组件，这样就会更加高效。
export default [
    {
        path: "/communication",
        component: () => import('@/views/Communication/Communication'),
        meta: {show: true},
        children: [
            {
                path: "attrs-listeners",
                component: () => import('@/views/Communication/AttrsListenersTest/AttrsListenersTest'),  
            },
            {
                path: "children-parent",
                component: () => import('@/views/Communication/ChildrenParentTest/ChildrenParentTest'),  
            },
            {
                path: "model",
                component: () => import('@/views/Communication/ModelTest/ModelTest'),  
            },
            {
                path: "event",
                component: () => import('@/views/Communication/EventTest/EventTest'),  
            },
            {
                path: "scope-slot",
                component: () => import('@/views/Communication/ScopeSlotTest/ScopeSlotTest'),  
            },
            {
                path: "sync",
                component: () => import('@/views/Communication/SyncTest/SyncTest'),  
            },

            {
                path: "/communication",
                redirect: "/communication/event"
            }
        ],
    },
    {
        path: "/center",
        component: () => import('@/views/Center'),
        children:[
            {
                path: "myorder",
                component: () => import('@/views/Center/myOrder'),
            },
            {
                path: "grouporder",
                component: () => import('@/views/Center/groupOrder'),
            },
            {
                // 跳转center，默认跳到myorder
                path: "/center",
                redirect: "/center/myorder"
            }
        ]
    },
    {
        path: "/home",
        component: () => import('@/views/Home'),
        meta: {show: true},
    },
    {
        path: "/login",
        component: () => import('@/views/Login'),
        meta: {show: false},
    },
    {
        path: "/register",
        component: () => import('@/views/Register'),
        meta: {show: false},
    },
    {
        path: "/search/:keyword?",
        component: () => import('@/views/Search'),
        meta: {show: true},
        name: "search",
        // props传参:  1、布尔类型 => 只能传params
        // props: true
        // 2、对象  => 额外的路由组件传参
        // props: {par: 1, que: 2}
        // 3、函数  => params, query
        props: ($route) => {
            return{
                keyword: $route.params.keyword,
                k: $route.query.k
            }
        }
        // 箭头函数只return出一个对象时加() => ({})
        // props: ($route) => ({keyword: $route.params.keyword, k: $route.query.k})
    },
    {
        path: "/detail/:skuId?",
        component: () => import('@/views/Detail'),
        meta: {show: true},
    },
    {
        path: "/addshopsuccess",
        name: "addshopsuccess",
        component: () => import('@/views/AddCartSuccess'),
        meta: {show: true},
    },
    {
        path: "/shopcart",
        component: () => import('@/views/ShopCart'),
        meta: {show: true},
    },
    {
        path: "/trade",
        component: () => import('@/views/Trade'),
        meta: {show: true},
        // 路由独享的守卫
        beforeEnter: (to, from, next) => {
            if(from.path == "/shopcart"){
                next();
            }else{
                next(false);
            }
        },
    },
    {
        path: "/pay",
        component: () => import('@/views/Pay'),
        meta: {show: true},
        // 路由独享的守卫
        beforeEnter: (to, from, next) => {
            if(from.path == "/trade"){
                next();
            }else{
                next(false);
            }
        },
    },
    {
        path: "/paysuccess",
        component: () => import('@/views/PaySuccess'),
        meta: {show: true},
    },

    {
        // 重定向，默认是首页
        path: "*",
        redirect: "/home",
    },
]
